package com.sk.waste.app.utils

import android.Manifest
import android.app.Activity
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.telephony.SmsManager
import android.util.DisplayMetrics
import android.widget.Toast
import com.lc.smc.lib.utils.LCBaseUtil


/**
 *  @time 2025/1/17  11:28
 *  @author Im_jingwei
 *  @desc 基础工具
 */
object BaseUtil {

    /**
     *  @time 2025/1/22  10:33
     *  @author Im_jingwei
     *  @desc 获取屏幕尺寸
     */
    fun getScreenMetrics(context: Context): DisplayMetrics {
        // 获取DisplayMetrics对象
        return context.resources.displayMetrics
    }

    /**
     *  @time 2025/1/22  10:33
     *  @author Im_jingwei
     *  @desc 获取屏幕高度
     */
    fun getScreenHeight(context: Context): Int {
        return getScreenMetrics(context).heightPixels
    }

    /**
     *  @time 2025/1/22  10:34
     *  @author Im_jingwei
     *  @desc 获取屏幕宽度
     */
    fun getScreenWidth(context: Context): Int {
        return getScreenMetrics(context).widthPixels
    }

    /**
     *  @time 2025/1/22  21:11
     *  @author Im_jingwei
     *  @desc 是否是平板模式
     */
    fun isPadDevice(context: Context): Boolean {
        return (getScreenWidth(context) > getScreenHeight(context))
    }

    /**
     *  @time 2025/9/8  11:07
     *  @author Im_jingwei
     *  @desc 隐藏姓名
     */
    fun getNameHideStr(title: String): String {
        return title.substring(0, 1) + "**"
    }

    /**
     *  @time 2025/9/8  11:07
     *  @author Im_jingwei
     *  @desc 隐藏电话
     */
    fun getPhoneHideStr(phone: String): String {
        return phone.substring(0, 3) + "********"
    }

    /**
     *  @time 2025/9/8  19:13
     *  @author Im_jingwei
     *  @desc 拨打电话
     */
    fun callPhone(mContext: Activity, number: String) {
        if (!PermissionUtil.instance.checkPermisssion(mContext, Manifest.permission.CALL_PHONE)) {
            LCBaseUtil.showToast(mContext, "电话权限被拒绝，请授权或打开设置允许访问拨打电话权限！")
            PermissionUtil.instance.requesetPermission(mContext, Manifest.permission.CALL_PHONE)
            return
        }

        val intent = Intent(Intent.ACTION_CALL)
        intent.setData(Uri.parse("tel:$number"))
        mContext.startActivity(intent)
    }

    fun copyClipboard(context: Context, msg: String) {
        val clipboard: ClipboardManager? = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager?
        val clip = ClipData.newPlainText("label", msg)
        clipboard?.setPrimaryClip(clip)
        Toast.makeText(context, "连接已复制到剪贴板,您可以分享此链接！", Toast.LENGTH_SHORT).show()
    }

    fun sendMsg(context: Context) {
        val phoneNumber = "18663763367"  // 替换为实际的电话号码
        val message = "废旧招标信息网，邀请您体验：https://waste.biddingcloud.cn/app_introduce.html"      // 替换为实际要发送的内容
        try {
            val smsManager: SmsManager = SmsManager.getDefault()
            smsManager.sendTextMessage(phoneNumber, null, message, null, null)
            Toast.makeText(context, "短信发送成功", Toast.LENGTH_SHORT).show()
        } catch (e: Exception) {
            Toast.makeText(context, "短信发送失败: ${e.message}", Toast.LENGTH_SHORT).show()
            e.printStackTrace()
        }
    }



}